<template>
<view class="cu-list menu">
  <view class="cu-item arrow border-top" @tap="checkQrCode">
    <view class="content">客服二维码</view>
    <view class="action text-xxl">
      <text class="cuIcon-qr_code"></text>
    </view>
  </view>
  <view class="cu-item arrow" @tap="makeCall">
    <view class="content">客服热线</view>
    <view class="action">{{contactInfo.contact}}</view>
  </view>
</view>
</template>

<script>
// TODO 点击客服热线, 拨打电话
export default {
  name: 'customer-service', // 联系客服
  data () {
    return {
      customerServiceInfo: []
    }
  },
  computed: {
    qrCodeInfo() {
      let target = {}
      if (this.customerServiceInfo.length) {
        target = this.customerServiceInfo.find(o => o.type === 2)
      }
      return target
    },
    contactInfo() {
      let target = {}
      if (this.customerServiceInfo.length) {
        target = this.customerServiceInfo.find(o => o.type === 1)
      }
      return target
    },
    qrCodeSrc() {
      return `${this.$BASE_URL}${this.qrCodeInfo.image}`
    }
  },
  onLoad() {
    this.getCustomerService()
  },
  methods: {
    getCustomerService() {
      this.$api.getCustomerService().then(res => {
        if (!res) return
        const resData = res.data
        this.customerServiceInfo = resData.list
      })
    },
    checkQrCode() {
      this.$Router.push({
        name: 'customer-service-qrCode',
        params: {
          src: this.qrCodeSrc
        }
      })
    },
    makeCall() {}
  }
}
</script>

<style lang="less">
</style>
